/*----------------------------------------------------------------------------
*         ATMEL Microcontroller Software Support  -  ROUSSET  -
*----------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. This includes without
* limitation any warranty or condition with respect to merchantability or
* fitness for any particular purpose, or against the infringements of
* intellectual property rights of others.
*----------------------------------------------------------------------------
* File Name           : Board.h
* Object              : AT91SAM7X Evaluation Board Features Definition File.
*
* Creation            : JG   20/Jun/2005
*----------------------------------------------------------------------------
*/
#ifndef Board_h
#define Board_h

#include "AT91SAM7X256.h"
#include "ioat91sam7x256.h"

#define true	-1
#define false	0

/*-------------------------------*/
/* SAM7Board Memories Definition */
/*-------------------------------*/
// The AT91SAM7X128 embeds a 32-Kbyte SRAM bank, and 128K-Byte Flash

#define  FLASH_PAGE_NB		256
#define  FLASH_PAGE_SIZE	128

/*-------------------------*/
/* Push Buttons Definition */
/*-------------------------*/

#define SW1_MASK        (1<<21)	// PA21
#define SW2_MASK        (1<<22)	// PA22
#define SW3_MASK        (1<<23)	// PA23
#define SW4_MASK        (1<<24)	// PA24
#define SW_MASK         (SW1_MASK|SW2_MASK|SW3_MASK|SW4_MASK)


#define SW1 	(1<<21)	// PA21
#define SW2 	(1<<22)	// PA22
#define SW3 	(1<<23)	// PA23
#define SW4 	(1<<24)	// PA24

//Hardware pinout
//RX - Rotary B
//D4 - SSD1306 CS
//D6 - Rotary A
//D8 - SSD1306 D/C
//D10 - SSD1306 RESET
//D11 - SSD1306 MOSI
//D13 - SSD1306 - SPCK

//Netdiono SPI0 pinout -> connecting to SSD1306
#define AT91C_PA12_NPCS0    (AT91C_PIO_PA12) //  SPI0 Peripheral Chip Select 0, D4
#define AT91C_PA16_MISO     (AT91C_PIO_PA16) //  SPI0 Master In Slave Out, D12
#define AT91C_PA17_MOSI     (AT91C_PIO_PA17) //  SPI0 Master Out Slave In, D11
#define AT91C_PA18_SPCK     (AT91C_PIO_PA18) //  SPI0 Serial Clock, D13
#define	AT91C_PB22_RESET	(AT91C_PIO_PB22) //  RESET, D10
#define	AT91C_PA4_DC		(AT91C_PIO_PA4)	 //  D/C, D8

//SD card SPI1 pinout
#define	AT91C_PA21_NPCS0	(AT91C_PIO_PA21)  // SPI1 CS0
#define	AT91C_PA22_SPCK		(AT91C_PIO_PA22)  // SPI1 Serial Clock
#define	AT91C_PA23_MOSI		(AT91C_PIO_PA23)  // SPI1 Master Out Slave In
#define	AT91C_PA24_MISO		(AT91C_PIO_PA24)  // SPI1 Master In Save out

//VS1053d shield SPI
#define	VS1053_PA16_MISO	AT91C_PA16_MISO		// MISO, D12
#define	VS1053_PA17_MOSI	AT91C_PA17_MOSI		// MOSI, D11
#define	VS1053_PA18_SCLK	AT91C_PA18_SPCK		// SCLK, D13
#define	VS1053_PB21_NPCS1	(AT91C_PIO_PB21)	// CS, D9

#define	VS1053_PA0_BSYNC	(AT91C_PIO_PA0)		// BSYNC, D2
#define	VS1053_PA1_DREQ		(AT91C_PIO_PA1)		// DREQ, D3
#define	VS1053_PA12_GPIO2	(AT91C_PIO_PA12)	// GPIO2, D4
#define	VS1053_PB19_GPIO3	(AT91C_PIO_PB19)	// GPIO3, D5

//Rotary encoder
#define	ROTARY_PB20_CHANNEL_A	(AT91C_PIO_PB20)	// Channel A, D6
#define	ROTARY_PA27_CHANNEL_B	(AT91C_PIO_PA27)	// Channel B, D0

//The following are defined for SPI Chip selection pins, not necessarily required
#define	AT91C_PA4_NPCS1		(AT91C_PIO_PA4)
#define AT91C_PA9_NPCS1		(AT91C_PIO_PA9)
#define	AT91C_PA30_NPCS2	(AT91C_PIO_PA30)
#define	AT91C_PA10_NPCS2	(AT91C_PIO_PA10)
#define	AT91C_PA3_NPCS3		(AT91C_PIO_PA3)
#define	AT91C_PA5_NPCS3		(AT91C_PIO_PA5)
#define	AT91C_PA22_NPCS3	(AT91C_PIO_PA22)

#define NETDUINO_PIO_LED1	(AT91C_PIO_PB27)	//Amber
#define NETDUINO_PIO_LED2	(AT91C_PIO_PB28)	//Green
#define	NETDUINO_PIO_LED3	(AT91C_PIO_PB23)	//Blue

#define SW1_CTRL_OF_RESET	(AT91C_PIO_PA30)

/*--------------*/
/* Master Clock */
/*--------------*/

#define EXT_OC          18432000   // Exetrnal ocilator MAINCK
#define MCK             47923200   // MCK (PLLRC div by 2)
#define	BOARD_MCK		48000000	//TODO: about 0.16% different than MCK, should combine these two.
#define MCKKHz          (MCK/1000) //

//TODO: remove the next line , it is from at91lib\boards\at91sam7s-ek\board.h
//original: DBGU pins definition. Contains DRXD (PA9) and DTXD (PA10). 0x00000600 (00000000 00000000 00000110 00000000)
//new: DRXD (PA27), DTXD (PA28). 0x18000000 (00011000 00000000 00000000 00000000)
#define PINS_DBGU  {0x18000000, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}

#endif /* Board_h */
